// pages/refundCause/refundCause.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //获取手机高度
    that.setData({
      navH: app.globalData.navHeight,
      opasid: options.opasid,
    });
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that= this;
    wx.request({
      url: app.globalData.url + 'getAfterSaleDetail',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        id: that.data.opasid
      },
      success: function (res) {
        that.setData({
          after: res.data.data,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  navBack: function () {
    wx.navigateBack({

    })
  },
  countTime: function (edTime) {
    //var edTime ='2020-02-21 22:33:27';
    var that = this;
    var date = new Date();
    var now = date.getTime();
    var endDate = new Date(that.data.edTime.replace(/\.|\-/g, '/'));//设置截止时间
    var end = endDate.getTime();
    var leftTime = end - now; //时间差                              
    var d, h, m, s, ms;
    if (leftTime >= 0) {
      d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
      h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
      m = Math.floor(leftTime / 1000 / 60 % 60);
      s = Math.floor(leftTime / 1000 % 60);
      ms = Math.floor(leftTime % 1000);
      ms = ms < 100 ? "0" + ms : ms
      s = s < 10 ? "0" + s : s
      m = m < 10 ? "0" + m : m
      h = h < 10 ? "0" + h : h
      that.setData({
        countdown: d + "天" + h + "时" + m + "分" + s + "秒",
      })
      //递归每秒调用countTime方法，显示动态时间效果
      setTimeout(that.countTime, 100);
    } else {
      console.log('已截止')
      that.setData({
        countdown: '00:00:00'
      })
    }
  },
  //获取几天后的日期
  getDateStr: function (today, addDayCount) {
    console.info(addDayCount);
    var dd;
    if (today) {
      dd = new Date(today);
    } else {
      dd = new Date();
    }
    dd.setDate(parseInt(dd.getDate()) + parseInt(addDayCount));//获取AddDayCount天后的日期 
    var y = dd.getFullYear();
    var month = dd.getMonth() + 1;//获取当前月份的日期 
    var d = dd.getDate();
    var h = dd.getHours();
    var m = dd.getMinutes();
    var s = dd.getSeconds();
    if (m < 10) {
      m = '0' + m;
    };
    if (d < 10) {
      d = '0' + d;
    };
    return y + "-" + month + "-" + d + " " + h + ':' + m + ':' + s;
  },
  refundCourier: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/pages/refundCourier/refundCourier?opasId=' + e.currentTarget.dataset.opasid,
    })
  },
  xiangqing:function(e){
    wx.navigateTo({
      url: '/pages/logistics/logistics?expressCompanyCode=' + e.currentTarget.dataset.code + '&trackingNumber=' + e.currentTarget.dataset.num + '&expressCompany=' + e.currentTarget.dataset.company + '&status=' + e.currentTarget.dataset.status
    })
  },
})